<?php

require_once 'Common/values.php';
require_once 'Common/theme.php';
require_once 'Common/database.php';
$userfolders='%'.$user.'%';

echo '<center><h3>Knowledge Base</h3>';
echo 'Search : <FORM action="index.php?p=kbsearch" method="POST"><input type="text" name="search"><input type="submit" value="Go"></FORM>';
echo '<p><table width="1000px" height="450px"><tr><td valign="top" width="15%">';
echo'<table>';
$result = mysql_query("SELECT * FROM tblkbfolders WHERE Users LIKE '$userfolders' OR Users = '$defaultgroup' OR Users = 'all' Order By `Folder`");
while($row = mysql_fetch_array($result))
{
echo '<tr><td class="noborder" onclick="display(folder'.$row[ID].');"><img src="img/folder.gif"> '.$row[Folder].'</td><td class="noborder" onclick=location=\'index.php?p=kbdeletefolder&l='.$row[ID].'\'><img src="img/delete.gif"></td></tr>';

$result1 = mysql_query("SELECT * FROM tblkb WHERE Folder ='$row[Folder]' Order By `Name`");
echo '<tr><td class="noborder"><div style="display:none;" id="folder'.$row[ID].'">';
echo '<table>';
while($row1 = mysql_fetch_array($result1))
{

echo '<tr><td class="noborder" width="10px"></td><td class="noborder" onclick="location=\'index.php?p=kb&l='.$row1[lognumber].'\'"><img src="img/sub_folder.gif"> '.$row1[Name].'</td><td class="noborder" onclick=location=\'index.php?p=kbdelete&l='.$row1[lognumber].'\'><img src="img/delete.gif"></td></tr>';

}
echo '<tr><td class="noborder"></td><td class="noborder" onclick="location=\'index.php?p=kbnew&f='.$row[Folder].'\'"><b>New</td></tr>';
echo '</table>';
echo '</div></td></tr>';
}
echo '<tr><td class="noborder" onclick="location=\'index.php?p=shadd&f2=kbfolders\'"><b>New</td></tr>';
echo '</table>';
$result=mysql_query("SELECT * FROM tblkb WHERE lognumber='$_GET[l]' Order By `Name`");
$row = mysql_fetch_array($result);
if($_GET[l]!='')
{
echo '<td valign="top"><center>
<table>
<form method="Post" Action="index.php?p=kbupdate">
<tr><td class="noborder">KB number :</td><td class="noborder"><input type="hidden" name="lognumber" value="'.$row[lognumber].'">'.$row[lognumber].'</td></tr>
<tr><td class="noborder">Folder :</td><td class="noborder"><input type="Text" Name="folder" value="'.$row[Folder].'"></td></tr>
<tr><td class="noborder">Subject : </td><td class="noborder"><input type="Text" Name="subject" value="'.$row[Name].'"></td></tr>
<tr><td class="noborder">Users : </td><td class="noborder"><input type="Text" Name="users" value="'.$row[Users].'"></td></tr>
<tr><td class="noborder"></td><td class="noborder" colspan="2"><input type="submit" value="Update"></td></tr>
</form>';

echo '<tr><td class="noborder" colspan="2">Documents:
';
$result = mysql_query("SELECT * FROM tblkbdocuments WHERE LogNumber='$_GET[l]' Order By `Document`");
echo '<table width="700px"><tr bgcolor="'.$colourtoprow.'"><td width="20px">Document number</td><td>Filename</td><td>Rev</td><td width="30px"></td><td width="30px"></td><td>Users</td></tr>';
while($row = mysql_fetch_array($result))
{
echo '<form method="Post" Action="index.php?p=kbupdatedoc"><tr><td><input type="hidden" name="docnumber" value="'.$row[DocNumber].'"> '.$row[DocNumber].'</td><td>';
if($row[Out]!='')
{
echo ''.$row[Document].'</td><td>'.$row[Rev].'</td><td><b>Out</td><td onclick="location=\'index.php?p=kbchange&doc='.$row[DocNumber].'\'">In</td></tr>';
}
else
{
echo '<a href="kb/documents/'.$row[Document].'">'.$row[Document].'</a></td><td width="20px">'.$row[Rev].'</td><td width="30px" onclick="location=\'index.php?p=kbout&doc='.$row[DocNumber].'\'">Out</td><td width="30px"><b>In</td><td><input type="text" value="'.$row[Users].'" Name="users"></td><td><input type="submit" Value="Update"></td></tr>';

}
echo '</form>';
}
echo'<tr><form method="Post" Action="index.php?p=kbupload&l='.$_GET[l].'" enctype="multipart/form-data"><td colspan="6"><input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
Choose a file to upload: <input type="hidden" name="lognumber"><input name="document" type="file"><input type="submit" value="Upload"></form></td></tr></table>
</td></tr>
</table>
</td></tr>';
}
else
{
echo '<td valign="top">Click on the folder icons on the left hand side</td></tr>';
}
echo '</table></center>';

?>
